//
//  ViewController.m
//  ios4
//
//  Created by blue on 15-11-24.
//  Copyright (c) 2015年 ZX. All rights reserved.
//

#import "ViewController.h"
#import "InputTableViewController.h"
@interface ViewController () <ZXDelegate>
{
<<<<<<< HEAD
    NSMutableArray * z;
    NSMutableArray * x;
=======
    NSArray * z;
    NSArray * x;
>>>>>>> dde7848aab438cfc7d15ca0c42cc1d3574b6c07a
    NSIndexPath * i;
    
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
   /* z = @[
          @"张鑫",
          @"繁星",
          @"肖遥"
          ];
    x = @[
          @"15073218429",
          @"18373259595",
          @"18098268462"
          ];*/
    NSUserDefaults * def = [NSUserDefaults standardUserDefaults];
<<<<<<< HEAD
  /*  [def setObject:z forKey:@"z"];
    [def setObject:x forKey:@"x"];
    [def synchronize];*/
    z= [[def objectForKey:@"z"] mutableCopy];
   x= [[def objectForKey:@"x"] mutableCopy];
    
    //
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(Editing :)];
    
}


- (void)Editing:(UIBarButtonItem * )ed
{
    [self.tableView setEditing:!self.tableView.editing animated:YES];
    ed.title = self.editing ? @"完成" : @"编辑";
    [self.tableView reloadData];
}

//最后一个的标识显示＋
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.row - z.count ? UITableViewCellEditingStyleDelete:UITableViewCellEditingStyleInsert;
}

//行的自定义
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tableView.isEditing ? z.count + 1 : z.count;
=======
//    [def setObject:z forKey:@"z"];
//    [def setObject:x forKey:@"x"];
//    [def synchronize];
    z= [def objectForKey:@"z"];
   x= [def objectForKey:@"x"];
    
    
}

//行的自定义
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return z.count;
>>>>>>> dde7848aab438cfc7d15ca0c42cc1d3574b6c07a
}

- (UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
<<<<<<< HEAD
    //显示行
    if (indexPath.row == z.count) {
        return cell;
    }
=======
>>>>>>> dde7848aab438cfc7d15ca0c42cc1d3574b6c07a
    cell.textLabel.text = z[indexPath.row];
    cell.detailTextLabel.text = x[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator ;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    InputTableViewController * cell = [[InputTableViewController alloc]initWithStyle:UITableViewStyleGrouped];
    UITableViewCell * con = [tableView cellForRowAtIndexPath:indexPath];
    //记录行数
    i = indexPath;
    cell.tel = con.detailTextLabel.text;
    cell.delegate = self;
   
    [self.navigationController pushViewController:cell animated:YES];
}

- (void)InputFish:(NSString * )text
{
    NSMutableArray * arr = x.mutableCopy;
    [arr replaceObjectAtIndex:i.row withObject:text];
    x = arr;
    NSUserDefaults * def = [NSUserDefaults standardUserDefaults];
    [def setObject:x forKey:@"x"];
<<<<<<< HEAD
//    [def synchronize];
    [self.tableView reloadData];
}

//删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [z removeObjectAtIndex:indexPath.row];
    [x removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
}
=======
    [def synchronize];
    [self.tableView reloadData];
}

>>>>>>> dde7848aab438cfc7d15ca0c42cc1d3574b6c07a
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
